var app = getApp();
Page({
  data: {
    // listclass:[{
    // }],
    curNav: 1,
    curIndex: 0 ,
    curP: undefined,
  },

  //事件处理函数 
 
  changeColor: function (e) {
    // 获取item项的id，和数组的下标值  
    let id = e.target.dataset.id,
    // 把点击到的某一项，设为当前index  
    index = parseInt(e.target.dataset.index),
    par = parseInt(e.target.dataset.pid),
    listNew = this.data.listclass;
    for(let j = 0 ;j < listNew[par].children.length;j++){
      listNew[par].children[j].ishaveChild = false;
      listNew[par].children[j].isActive = false;
    };
    listNew[par].children[index].ishaveChild = true;
    listNew[par].children[index].isActive = true;
    this.setData({
      curNav: id,
      curIndex: index,
      listclass: listNew
    })
  },
  // 分类页跳转
  skip: function (e) {
    var id = e.currentTarget.dataset.id;  //三级id
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/classes/get_id',
      data: {
        id: id,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        wx.navigateTo({
          url: "/pages/yiguo/cakes/cakes?ids=" + res.data.id + "&kinds=" + res.data.name,
        })
      },
    })
  },
  /*** 生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that = this;
    var listclass;
    console.log(options)
    var shopid = app.whereId.shopid;
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/classes/index',
      data: {
        shopid: shopid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        console.log(res);
        let list = res.data.listclass,
          isActive = "";
        
        for (let i = 0; i < list.length; i++) {
          if (list[i].children.length>0){
            list[i].children[0].isActive = true;
            list[i].children[0].ishaveChild = true;
          }else{
            }
        }
        that.setData({
          listclass: list,
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})